﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cofe.Core.Implements;
using Cofe.Core.Service;
using Cofe.Data;

namespace Cofe.Core
{
    [Obsolete("Use ModuleBootStrapper")]
    public class ManualBootStrapper : BootStrapperBase
    {       
        protected bool _allowReregister;
        private ICofeService[] _additionalServices;

        public ManualBootStrapper(bool allowReregister = false, params ICofeService[] additionalServices)
        {
            _allowReregister = allowReregister;
            _additionalServices = additionalServices;
        }

        protected virtual void ConfigureServiceImporter(ManualServiceImporter msi)
        {
            msi.RegisterCOFECore();
            msi.RegisterService(_additionalServices);
        }

        public override IServiceImporter ConfigureServiceImporter()
        {
            ManualServiceImporter msi = new ManualServiceImporter();
            ConfigureServiceImporter(msi);
            return msi;
        }

        public override void Run(params ICofeService[] additionalServices)
        {
            if (!_allowReregister)
                if (CofeServices.ServiceImported)
                    return;
            base.Run(additionalServices);
        }
    }
}
